Converts a string comparison or numeric comparison to a Boolean expression, or converts a single numeric expression to a Boolean expression.
文字列や数値の比較演算結果、および単独の数値表式をブール型の表式に変換します。
CBool (Expression1 {= | <> | < | > | <= | >=} Expression2) or CBool (Number)
CBool (Expression1 {= | <> | < | > | <= | >=} Expression2) あるいは CBool (Number)
Bool
ブール型
Expression1, Expression2: Any string or numeric expressions that you want to compare. If the expressions match, the CBool function returns True, otherwise False is returned.
Expression1, Expression2: 比較する文字列および数値の表式。CBool 関数は、2 つの表式が一致すれば True を返し、それ以外の場合は False を返します。
Number: Any numeric expression that you want to convert. If the expression equals 0, False is returned, otherwise True is returned.
Number: 変換させる数値表式。表式が 0 に等しい場合は False を返し、それ以外の場合は True を返します。
The following example uses the CBool function to evaluate the value that is returned by the Instr function. The function checks if the word "and" is found in the sentence that was entered by the user.
下記の例は、Instr 関数から返される値を、CBool 関数を使って評価させています。この関数は、ユーザーの入力する文字列の中に「and」という単語が含まれているかを判定します。
Sub ExampleCBool
Sub ExampleCBool
Dim sText As String
Dim sText As String
sText = InputBox("Please enter a short sentence:")
sText = InputBox("Please enter a short sentence:")
REM Proof if the word »and« appears in the sentence.
REM 入力した文字列中に「and」があるかを調べます。
REM Instead of the command line
REM 通常こうした判定には下記のような IF 文を使います。
REM If Instr(Input, "and")<>0 Then...
REM If Instr(Input, "and")<>0 Then...
REM the CBool function is applied as follows:
REM ここではその代わりに CBool 関数を使って判定をしています。
If CBool(Instr(sText, "and")) Then
If CBool(Instr(sText, "and")) Then
MsgBox "The word »and« appears in the sentence you entered!"
MsgBox "入力した文字列中に「and」があります。
EndIf
EndIf
End Sub
End Sub